<template>
	<view class="lc-numberBox-a" v-if="inputValue == 0">
		<view class="lc-add none" 
		@click="add" 
		:style="{'color':color,}"
		>
		+
		</view>
	</view>
	<view class="lc-numberBox-b" v-else>
		<view class="lc-minus"
		@click="minus" 
		:style="{'color':color}"
		>
		-
		</view>
		<view class="lc-number">
			<input type="number" :disabled="isDisabled" v-model="inputValue" :style="{ width: inputValue.toString().length * 20 + 'rpx' }" />
		</view>
		<view class="lc-add " 
		@click="add" 
		:style="{'color':color,}"
		>
		+
		</view>
	</view>
</template>

<script>
export default {
	name: 'lc-number-box',
	props: {
		value: {
			type: [Number, String],
			default: 1
		},
		min: {
			type: Number,
			default: 0
		},
		max: {
			type: Number,
			default: 99
		},
		step: {
			type: Number,
			default: 1
		},
		disabled: {
			type: Boolean,
			default: false
		},
		color: {
			type: [Number, String],
			default: '#FFFFFF'
		},
		fillet:{
			type: Boolean,
			default: true
		},
	},
	created() {
		this.inputValue = +this.value;
		this.isDisabled = this.disabled;
		this.inputStep=parseFloat(this.step);
	},
	data() {
		return {
			inputValue: 0,
			isDisabled:false,
			inputStep:1
		};
	},
	watch: {
		value(val) {
			this.inputValue = +val;
		},
		// inputValue(newVal, oldVal) {
		// 	if (+newVal !== +oldVal) {
		// 		this.$emit('change', newVal);
		// 	}
		// }
	},
	methods: {
		minus() {
			if(parseInt(this.inputValue)-parseInt(this.inputStep)<this.min){
				return;
			}
			this.inputValue=parseInt(this.inputValue)-parseInt(this.inputStep);
			this.$emit('cut',this.inputValue)
		},
		add() {
			if(parseInt(this.inputValue)+parseInt(this.inputStep)>this.max){
				return;
			}
			this.inputValue=parseInt(this.inputValue)+parseInt(this.inputStep);
			this.$emit('add',this.inputValue)
		}
	}
};
</script>

<style lang="scss">

.lc-numberBox-a {
	display: flex;
	flex-direction: row;
	align-items: center;
	justify-content: center;
	.lc-add.none{
		display: flex;
		position: absolute;
		justify-content: center;
		align-items: center;
		width: 52rpx;
		height: 52rpx;
		border-radius: 28rpx;
		font-size: 28rpx;
		color: #FFFFFF;
		background-color: #FE7701;
		line-height: 52rpx;
		right: 32rpx;
		top: 10rpx;
	}
}
.lc-numberBox-b{
	display: flex;
	flex-direction: row;
	align-items: center;
	justify-content: center;
	width: 104rpx;
	height: 52rpx;
	background-color: #FE7701;
	border-radius: 28rpx;
	position: absolute;
	right: 26rpx;
	top: 10rpx;
	.lc-minus{
		display: flex;
		position: absolute;
		justify-content: center;
		align-items: center;
		left: 12rpx;
		height: 52rpx;
		width: 18rpx;
		line-height: 52rpx;
		font-size: 28rpx;
		font-weight: 700;
	}
	.lc-add {
		display: flex;
		position: absolute;
		justify-content: center;
		align-items: center;
		right: 20rpx;
		height: 52rpx;
		width: 18rpx;
		line-height: 52rpx;
		font-size: 28rpx;
		font-weight: 700;
	}
	.lc-number{
		height: 48rpx;
		display: block;
	}
	.lc-number input{
		height: 52rpx;
		line-height: 52rpx;
		font-size: 28rpx;
		font-weight: 400;
		color: #FFFFFF;
	}
}
</style>
